﻿@model List<CMP.ERP.Model.PorBuy>
@{
    Layout = null;
}
@Html.Action("Account_Show", "Account");
    <div class="content">
        <div class="right" id="mainFrame">
            <div class="right_cont">
    <div class="header">
        <div class="header-right">
         
            <div id="modal-container-973559" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:1000px; margin-left:-490px;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">
                        采购订单系统
                    </h3>
                </div>
                <div class="modal-body">
                    <table class="table table-hover table-bordered " style="width:960px;text-align:center;margin:0 auto;border:1px solid #428bca;">

                        <tbody>
                            <tr>
                                <td>单据编码:</td>
                                <td><span id="PorBuy_Cid">@Session["num"]</span></td>
                            <tr>
                                <td>供应商:</td>
                                <td>
                                    <select id="Supplier">
                                        <option>--请选择--</option>
                                    </select>
                                </td>
                                <td>仓库:</td>
                                <td>
                                    <select id="WareHouse">
                                        <option>--请选择--</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td><input id="Button1" type="button" value="查询" style="margin-top:0;background-color:#4cff00;border-radius:15px;width:200px" onclick="sor1()" /></td>
                                <td><input type="text" name="PorBuy_Cid2" style="width:150px;" placeholder="输入商品名称"/></td>
                            </tr>
                        </tbody>
                    </table>
                    <table class="table table-hover table-bordered " style="width:960px;text-align:center;margin:0 auto;border:2px solid #428bca;" id="pss">
                        <thead>
                            <tr>
                                <th>请选择</th>
                                <th>商品编号</th>
                                <th>商品名称</th>
                                <th>编码</th>
                                <th>重量</th>
                                <th>备注</th>
                                <th>类型</th>
                                <th>价格</th>
                                <th>数量</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button> <button type="button" class="btn btn-default" id="cctv" onclick="funwe()" aria-hidden="true"><span class="icon-inbox"></span>保存</button>
                </div>
            </div>
         
        </div>
    </div>
    <!-- 顶部 -->
    <div id="middle">
      
        <div class="Switch"></div>
        <script type="text/javascript">
            $(document).ready(function (e) {
                $(".Switch").click(function () {
                    $(".left").toggle();

                });
            });
        </script>

        <div class="right" id="mainFrame">

            <div class="right_cont">
                <ul class="breadcrumb">
                    当前位置：
                    <a href="/Home/Index">首页</a>
                    <span class="divider">/</span>
                    采购订单
                </ul>
                <div class="title_right"><strong>采购订单</strong></div>
                <div style="width:100%; margin:auto">
                    <div>
                        <form method="get" action="/Procurement/SelPorBuy">
                            <table>
                                <tr>
                                    <td>从:</td>
                                    <td><input type="text" name="StartTime" class="laydate-icon span1-1" id="Calendar" /></td>
                                    <td>至:</td>
                                    <td><input type="text" name="End_Time" class="laydate-icon span1-2" id="Calendar2"  /></td>
                                    <td><button type="submit" class="btn btn-default" style="margin-bottom:10px"><span class="icon-search"></span>查询 </button></td>
                                    <td><button id="modal-973559" href="#modal-container-973559" role="button" type="button" class="btn btn-default" data-toggle="modal" style="margin-bottom:10px"><span class="icon-plus"></span>新增</button></td>
                                </tr>
                            </table> 
                        </form>
                    </div>
                    <div style="margin-top:20px;">
                        <table class="table  table-hover table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th style="text-align:center">编号</th>
                                    <th style="text-align:center">业务日期</th>
                                    <th style="text-align:center">单据编码</th>
                                    <th style="text-align:center">商品总额</th>
                                    <th style="text-align:center">供应商</th>
                                    <th style="text-align:center">仓库</th>
                                    <td style="text-align:center">采购单状态</td>
                                    <td style="text-align:center">操作</td>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model)
                                {
                                    <tr>
                                        <td style="text-align:center">@item.Pid</td>
                                        <td style="text-align:center">@item.PorBuy_Date</td>
                                        <td style="text-align:center">@item.PorBuy_Cid</td>
                                        <td style="text-align:center">@item.PorBuy_SumMoney</td>
                                        <td style="text-align:center">@((ViewBag.Supplier_Id as List<CMP.ERP.Model.Supplier>).Where(p => p.Supplier_Id == item.Supplier_Id).FirstOrDefault().Supplier_Name)</td>
                                        <td style="text-align:center">@((ViewBag.WareHose_Id as List<CMP.ERP.Model.WareHose>).Where(p => p.WareHose_Id == item.WareHose_Id).FirstOrDefault().WareHose_Name)</td>
                                        <td style="text-align:center">
                                            @if (@item.Por_Status == 1)
                                            {
                                                <p>已审核</p>
                                            }
                                            else
                                            {
                                                <a>未审核</a>
                                            }

                                        </td>
                                        <td>
                                            @if (@item.Por_Status == 1)
                                            {
                                                <span>审核完毕</span>
                                            }
                                            else
                                            {
                                                <span><a href="/Procurement/Xiangqing/@item.Pid">审核入库</a></span>
                                            }
                                            |<a onclick="del(@item.Pid)"><span class="icon-remove"></span>删除</a>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>

            </div>
        </div>
    </div>
            </div>
        </div>
    </div>
  

    <script>
  
        //显示商品数据信息
        $(function () {
            //$.ajax({
            //    type: "get",
            //    url: "/Procurement/show",
            //    success: function (data) {
                  
            //        $(data).each(function (index, item) {

            //            var pup = "<tr><td style='text-align:center'><input id='Checkbox" + item.Commodity_Id + "' type='checkbox' value='" + item.Commodity_Id + "' name='ck'/></td><td>" + item.Commodity_Id + "</td><td>" + item.Commodity_Name + "</td><td>" + item.Commodity_number + "</td><td>" + item.Commodity_Weight + "</td><td>" + item.Commodity_Remark + "</td><td>" + item.CommodityType_Name + "</td><td name='ck' id='ss" + item.Commodity_Id + "'>" + item.Commodity_Price + "</td><td><input name='pc' id=" + item.Commodity_Id + " type='text' style='width:147px' /></td></tr>";
            //            $("#pss tbody").append(pup);
            //        })
            //    }
            //})
            //获取供应商的下拉框数据信息
            $.ajax({
                type: "post",
                url: "/Procurement/Experss_Show",
                success: function (d) {

                    $(d).each(function (index, item) {

                        var apen = '<option id="name' + item.Supplier_Id + '" value="' + item.Supplier_Id + '">' + item.Supplier_Name + '</option>';
                        $("#Supplier").append(apen);
                    });
                }
            })
            //获取仓库数据信息
            $.ajax({
                type: "get",
                url: "/Procurement/calendar_Show",
                success: function (d) {

                    $(d).each(function (index, item) {

                        var apen = '<option id="cp' + item.WareHose_Id + '" value="' + item.WareHose_Id + '">' + item.WareHose_Name + '</option>';
                        $("#WareHouse").append(apen);
                    });
                }
            })
        })
        //实现采购订单功能
        function funwe() {
            alert($("#PorBuy_Cid").html());
            var options1 = $("#WareHouse option:selected");
            var option = $("#Supplier option:selected");
            ($(":checkbox").each(function () {

                if ($(this).attr("checked") == "checked") {
                    var sup = $(this).val();
                }
            }));
            var num = "";
            var selectvalue = "";
            var price = "";
            var emplist = $("[name='ck']:checked");
            $(emplist).each(function (index, p) {
                ss = $(p).val();
                num += $("#" + ss + "").val() + ",";
                price += $("#ss" + ss + "").html() + ",";
                if (selectvalue.length > 0) {
                    selectvalue += ",";
                }
                selectvalue += $(p).val();
            })
            num = num.substr(0, num.length - 1);
            price = price.substr(0, price.length - 1);
            $.ajax({
                type: "post",
                url: "/Procurement/cer",
                data: {
                    PorBuy_Cid: $("#PorBuy_Cid").html(),
                    Por_num: num,
                    Supplier_Id: option.val(),
                    WareHose_Id: options1.val(),
                    Commodity_Id: selectvalue,
                    Commodity_price: price
                },
                success: function (data) {
                    if (data == "True") {
                        alert("Ok");
                        location.href = "/Procurement/Procurement_Show";
                    }
                    else {
                        alert("No");
                    }
                },
                error: function () {

                    alert("失败,粗错了");
            }
            })
        }
        function del(id) {
      
            $.ajax({
                type: "post",
                url: "/Procurement/DEL",
                data: {
                    Pid: id,
                },
                success: function (data) {
                    if (data == "True") {
                        alert("Ok");
                        location.href = "/Procurement/Procurement_Show";
                    }
                    else {
                        alert("No");
                    }
                },
                error: function () {

                    alert("失败,粗错了");
                }
            })
        }
        function sor1() {
            var ss = $("[name='PorBuy_Cid2']").val();
            $.ajax({
                type: "get",
                url: "/Procurement/SearchByName",
                data: {
                    name: ss
                },
                success: function (data) {
                    $(data).each(function (index, item) {
                        var pup = "<tr id='P"+ item.Commodity_Id +"' value='"+ item.Commodity_Id +"'><td><input id='Checkbox" + item.Commodity_Id + "' type='checkbox' value='" + item.Commodity_Id + "' name='ck'/></td><td>" + item.Commodity_Id + "</td><td>" + item.Commodity_Name + "</td><td>" + item.Commodity_number + "</td><td>" + item.Commodity_Weight + "</td><td>" + item.Commodity_Remark + "</td><td>" + item.CommodityType_Name + "</td><td name='ck' id='ss" + item.Commodity_Id + "'>" + item.Commodity_Price + "<td><input name='pc' id=" + item.Commodity_Id + " type='text' /></td></tr>";
                        if($("#P"+ item.Commodity_Id +"").length>0)
                        {
                            alert("此商品已存在");
                        }
                        else
                        {
                            $("#pss tbody").append(pup);
                        }
                    })
                }
            })
        }
    </script>

</body>









